# 用户输入 分别是start end step，闭区间
start=$1
end=$2
step=$3
# 一阶段的tar包命名
one_step="redis-checkpoint.tar.gz"
two_step1="redis-pre-checkpoint_1.tar.gz"
two_step2="redis-pre-checkpoint_2.tar.gz"

createAndAddData() {
  # params:
  # 1: send data to redis count
  podman run -d -p 6379:6379 my-redis
  sr -e $1
  sleep 1
}

echo "start: $start, end: $end, step: $step"
for ((i = start; i <= end; i = $(expr $i + $step))); do
  echo ----------------------------------------
  echo --send-data--
  echo "${i}"
  mkdir -p "redis-test-${i}"
  cd "redis-test-${i}"

  createAndAddData ${i}
  echo --cp-stats--
  podman stats -l --no-stream --no-reset --format=json

  echo --cp-time-checkpoint--
  time podman container checkpoint -e ${one_step} -l
  podman rm -f -l

  echo --cp-time-restore--
  time podman container restore -i ${one_step}
  podman rm -f -l

  echo --cp-tar-size--
  ls -lu ${one_step}


  echo "start two-step checkpoint"
  createAndAddData ${i}
  echo --pcp-stats--
  podman stats -l --no-stream --no-reset --format=json

  echo --pcp-time-pre-checkpoint--
  time podman container checkpoint -P -e ${two_step1} -l

  echo --pcp-time-checkpoint--
  time podman container checkpoint -e ${two_step2} --with-previous -l
  podman rm -f -l

  echo --pcp-time-restore--
  time podman container restore -i ${two_step2} --import-previous ${two_step1}
  podman rm -f -l

  echo --pcp-pre-tar-size--
  ls -lu ${two_step1}

  echo --pcp-tar-size--
  ls -lu ${two_step2}

  cd ../
done
